package ro.dta.idbi.model;

import java.util.Hashtable;
import java.util.List;
import java.util.regex.Matcher;

import ro.dta.idbi.interfaces.IPrimitiveParser;

/**
 * Foreign key column parser for the add,extend,delete and contract BAV
 * transformations
 * 
 * @author Tudor Dobrila
 * 
 */
public class AddFkParser implements IPrimitiveParser {

	@Override
	public Hashtable<String, Object> parse(Matcher matcher) {
		Hashtable<String, Object> result = new Hashtable<String, Object>();
		result.put("type", "foreignkey");
		result.put("fulldef", matcher.group(1));
		result.put("name", matcher.group(2));
		result.put("sourcetable", matcher.group(3));
		List<String> cols = AbstractPrimitivePattern.getColumns(matcher.group(4));
		result.put("sourcecols", cols);
		result.put("targettable", matcher.group(8));
		cols = AbstractPrimitivePattern.getColumns(matcher.group(9));
		result.put("targetcols", cols);
		return result;
	}
}
